home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / harderr.zip / TIMEBOOT.ASM < prev    next >
Assembly Source File  |  1991-08-31  |  8KB  |  206 lines

  1. ; Program Name    : timeboot.asm
  2. ; Author          : bill buckels
  3. ; Date            : Sept 1, 1991
  4. ; Function        : tsr program to reboot an IBM PC if a keypress
  5. ;                   does not occur within the time limit in minutes
  6. ;                   as specified on the command line.
  7. ;                   if the entry is not in the range of 1-9
  8. ;                   a default of 5 minutes is assumed.
  9. ;                   it is meant to be used during interactive
  10. ;                   periods only... potential for damage exists.
  11.  
  12.  
  13. cr            equ  0dh               ;carriage return
  14. lf            equ  0ah               ;line feed
  15.  
  16. CODE          SEGMENT PARA PUBLIC 'CODE'
  17.               ASSUME CS:CODE
  18.               ORG 100h
  19.  
  20. BEGIN:        jmp INITIALIZE         ;jump to initialization code
  21.  
  22.  
  23. old_int_9h         label dword       ;old keyboard interrupt vector
  24. old_keyboard_int   dw 2 dup (?)
  25.  
  26. old_int_1ch        label dword       ;old timer interrupt vector
  27. old_timer_int      dw 2 dup (?)
  28.  
  29. target             dw 1092           ; 1092 ticks per minute
  30. timecheck          dw 0              ; counter is set to zero
  31. minutes            db 5              ; default multiplier is 5 minutes
  32.  
  33. REBOOT:   ;INTEL 8088 machine language instructions
  34.           ;to duplicate the ctrl-alt-del key combo
  35.           ;and reboot the machine.
  36.  
  37.           DB 0B8h, 040h, 000h             ;mov  ax, 0040h
  38.           DB 050h, 007h                   ;push ax
  39.           DB 026h, 0C7h                   ;pop  es
  40.           DB 006h, 072h, 000h, 034h, 012h ;mov word ptr [0072h], 1234h
  41.           DB 0EAh, 000h, 000h, 0FFh, 0FFh ;jmp 0ffffh:0000h
  42.  
  43. ;-------------------------------------------------------
  44. ;Resident mainline and Front-end routine for the timer
  45. ;interrupt handler. Execution is vectored here 18.2 ticks
  46. ;per second and a counter is incremented.
  47. ;If the counter reaches the target the computer reboots.
  48. ;-------------------------------------------------------
  49.  
  50. TIMERTICK     PROC NEAR
  51.               sti              ;enable interrupts
  52.               push ax          ;save registers
  53.               push bx
  54.               push cx
  55.               push dx
  56.               push si
  57.               push di
  58.               push ds
  59.               push es
  60.  
  61.               inc timecheck         ;increment the timecheck
  62.               mov ax,timecheck
  63.               mov bx,target         ;compare the counter to the target
  64.               cmp bx,ax
  65.               jbe REBOOT            ;reboot the machine if time is up
  66.  
  67.               pop es                ;otherwise restore the registers
  68.               pop ds
  69.               pop di
  70.               pop si
  71.               pop dx
  72.               pop cx
  73.               pop bx
  74.               pop ax
  75.               jmp old_int_1ch   ;goto BIOS timertick routine
  76.  
  77. TIMERTICK     ENDP
  78.  
  79. ;-------------------------------------------------------
  80. ;Resident mainline and Front-end routine for the keyboard
  81. ;interrupt handler. Execution is vectored here whenever
  82. ;an interrupt 9 is generated by the keyboard.
  83. ;Each time a key is pressed a counter is reset to 0.
  84. ;-------------------------------------------------------
  85.  
  86. KEYPRESS      PROC NEAR
  87.               sti              ;enable interrupts
  88.               push ax          ;save registers
  89.               push bx
  90.               push cx
  91.               push dx
  92.               push si
  93.               push di
  94.               push ds
  95.               push es
  96.  
  97.               mov timecheck,0  ;set the timer check to zero
  98.  
  99.               pop es           ;restore registers
  100.               pop ds
  101.               pop di
  102.               pop si
  103.               pop dx
  104.               pop cx
  105.               pop bx
  106.               pop ax
  107.               jmp old_int_9h   ;goto BIOS keyboard routine
  108.  
  109. KEYPRESS      ENDP
  110.  
  111. ;------------------------------------------------------------
  112. ;         RESIDENT PORTION ENDS *** TRANSIENT PORTION STARTS
  113. ;------------------------------------------------------------
  114.  
  115. ;------------------------------------------------------------
  116. ;initialization message - the requested time limit is inserted here
  117. ;------------------------------------------------------------
  118. TITLE1$ db '╔═════════════════════════════════════════╗',cr,lf
  119.         db '║  TIMEBOOT(C) by Bill Buckels 1991       ║',cr,lf
  120.         db '║  USAGE is   : "TIMEBOOT [minutes 1-9]"  ║',cr,lf
  121.         db '║  DEFAULT is : "TIMEBOOT 5"              ║',cr,lf
  122.         db '╚═════════════════════════════════════════╝',cr,lf
  123.         db 'This Computer Will REBOOT If A Key Is Not Pressed For ','$'
  124.  
  125. TITLE2$ db '5 MINUTES.',cr,lf,'$'
  126.  
  127. ;------------------------------------------------------------
  128. ;LIST$ writes a string to stdout
  129. ;------------------------------------------------------------
  130. LIST$ PROC NEAR
  131.       push ax
  132.       mov ah,9h ; call dos function 9H
  133.       int 21h
  134.       pop ax
  135.       ret
  136. LIST$ ENDP
  137.  
  138. ;----------------------------------------------------------------
  139. ;INITIALIZE performs tasks to set the stage for the resident part
  140. ;of the program.
  141. ;-----------------------------------------------------------------
  142. INITIALIZE    PROC NEAR
  143.  
  144. ;let them know who we are
  145.  
  146.          lea dx, TITLE1$
  147.          call LIST$
  148.                                ; get command line arg from psp:82h
  149.          MOV BX,82h            ; point at first character in arg
  150.          MOV DL,BYTE PTR[BX]   ; and move it into dl
  151.          SUB DL, '0'           ; change from ascii to numeric
  152.          CMP DL, 1             ; is it below 1
  153.          JB  SKIPIT            ; if so skipit
  154.          CMP DL, 9             ; is it above 9
  155.          JA  SKIPIT            ; if so skipit
  156.          MOV minutes,DL        ; change the muliplier if in range
  157.          ADD DL, '0'           ; make it ascii again and
  158.          MOV TITLE2$, DL       ; update the string with the new time
  159.  
  160. SKIPIT:  LEA DX,TITLE2$
  161.          CALL LIST$            ;print the confirmation of the time
  162.  
  163.          MOV  AX,target
  164.          SUB  DX,DX            ;build the target time in clock ticks
  165.          MOV  DL,minutes
  166.          IMUL DX
  167.          MOV  target, AX
  168.  
  169. ;Now save the keyboard vector and replace it
  170. ;with one pointing to the
  171. ;code that we will leave behind in memory.
  172.  
  173.               mov ah,35h                    ;get current interrupt 9 vector
  174.               mov al,9
  175.               int 21h
  176.               mov old_keyboard_int,bx       ;save vector offset
  177.               mov old_keyboard_int[2],es    ;save vector segment
  178.               mov ah,25h                    ;set new vector
  179.               mov al,9
  180.               lea dx,KEYPRESS               ;point it to new handler
  181.               int 21h
  182.  
  183. ;Now save the timer vector and replace it
  184. ;with one pointing to the
  185. ;code that we will leave behind in memory.
  186.  
  187.               mov ah,35h                 ;get current interrupt 1C vector
  188.               mov al,1ch
  189.               int 21h
  190.               mov old_timer_int,bx       ;save vector offset
  191.               mov old_timer_int[2],es    ;save vector segment
  192.               mov ah,25h                 ;set new vector
  193.               mov al,1ch
  194.               lea dx,TIMERTICK           ;point it to new handler
  195.               int 21h
  196.  
  197. ;Exit thru INT 27h and reserve enough room
  198. ;the offset of TITLE1$ is a marker to end of resident code
  199.  
  200.               mov dx,offset TITLE1$         ;reserve space for code
  201.               int 27h                       ;terminate-but-stay-resident
  202. INITIALIZE    ENDP
  203. ;
  204. CODE          ENDS
  205.               END BEGIN
  206.